﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Common;

namespace Hospital
{
    public partial class PatientSearchUserControl : UserControl
    {
        public event Hospital.MainForm.PatientSearchHandler patientSearchEvent;
        public PatientSearchUserControl()
        {
            InitializeComponent();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            StringBuilder strErrorMsg = new StringBuilder();
            if (!Validator.checkRequired(this.tbPatientId.Text))
            {
                strErrorMsg.Append("请输入编号\n");
            }
            else if (this.tbPatientName.Text.Trim() ==string.Empty && PatientDao.getById(Int32.Parse(this.tbPatientId.Text.Trim())) == null)
            {
                strErrorMsg.Append("此编号不存在\n");
            }else if(this.tbPatientName.Text.Trim()!=string.Empty && PatientDao.getByIdAndName(Int32.Parse(this.tbPatientId.Text.Trim()),this.tbPatientName.Text.Trim()) == null)
            {
                strErrorMsg.Append("此编号与姓名不存在\n");
            }
                if (strErrorMsg.Length > 0)
            {
                MessageBox.Show(strErrorMsg.ToString(), "出错提示");
                return;
            }

            this.patientSearchEvent(Int32.Parse(this.tbPatientId.Text.Trim()),this.tbPatientName.Text.Trim());
        }

    }
}
